package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Region;
import org.hxyjs.entity.Region;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.RegionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/regionController")
public class RegionController {
	@Resource
	RegionService regionService;
	@RequestMapping("/getAllRegion")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Region> getAllRegion() throws Exception {
    	System.out.println("查询全部地区");
		return regionService.getAllRegions();
    }

	@RequestMapping("/deleteRegionByRno/{rno}")
	@ResponseBody
    public DTO<Region> deleteRegionByRno(@PathVariable("rno") String rno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(rno+"删除地区");
    	return regionService.deleteRegionByRno(rno);
    }

	@RequestMapping("/updateRegionByRno")
	@ResponseBody
	public DTO<Region> updateRegionByRno(@RequestBody Region region) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改地区");
		return regionService.updateRegionByRno(region);
	}


	@RequestMapping("/addRegion")
	@ResponseBody
	public DTO<Region> addRegion(@RequestBody Region region) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加地区");
		System.out.println(region);
 		return regionService.addRegion(region);
	}
	@RequestMapping("/getRegionByPage")
	@ResponseBody
	public DTO<Region> getRegionByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return regionService.getRegionByPage(pageInfo);
	}

}